<?php
/**
 * 位置调用接口
 * $this->S;
 * $this->table_sortMap
 * 
 * @author 叶风
 * Qq:    355007778
 * Email: ye.fn@163.com
 */

namespace m;
trait info_g
{
    /**
     * 
     * @param type $sid 类别
     * @param type $l 条数
     * @param type $order 排序
     * @return type
     */
    function li($sid, $l=5, $order='id desc')
    {
        $t = array('t1'=>array('as'=>$this->table));
        $w = 't1.state>0';
        
        if ($sid){
            $sid = $this->S->ids_sub($sid);
            $t['sm'] = array('as'=>$this->table_sortMap, 'join'=>'JOIN','on'=>'sm.data_id=t1.id');
            $w = "sm.sort_id IN($sid) AND ". $w;
         }
        return $this->db->get($t, '*', $w, $order, $l);
    }
    

    /**
     * 
     * @param type $a
     * @return array(); id, title
     */
    function cp_recom($a)
    {
        $t = array('t1'=>array('as'=>$this->table),
                't2'=> array('as'=>'layout_plate_item', 'join'=>'RIGHT JOIN','on'=>'t2.data_id=t1.id AND t1.state>0'));
        
        $l = intval($a['li']);
        $l or $l=100;
        $pl_id = intval($a['plate_id']);
        $w = 't2.plate_id='. $pl_id .'';
        return $this->db->get($t, 't1.*, t2.data_id id, t2.ordering, t2.id layout_plate_item_id', $w, 't2.ordering DESC, t2.id DESC', $l);
    }
	
	function cp_li($a)
    {
        $A = array('title asc', 'hits desc');
        $order = in_array($a['order'], $A)? $a['order'] : 'id desc';
        $sid = intval($a['sid']=='auto'? $_GET['sid'] : $a['sid']);
        return $this->li($sid, intval($a['li']), $order);
    }
}
